package com.huichenghe.xinlvsh01.Adapter;

import android.app.ActionBar;
import android.content.Context;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.huichenghe.xinlvsh01.CustomView.HistogramImageView;
import com.huichenghe.xinlvsh01.R;

/**
 * 柱状图适配器, 呈现计步和卡路里
 * Created by lixiaoning on 15-11-13.
 */
public class HistogramAdapter extends SuperAdapter
{
    public static final String TAG = HistogramAdapter.class.getSimpleName();
    // ViewHolder 里边有一个自定义的柱状图控件对象
    class LocalViewHolder extends ViewHolder
    {
       HistogramImageView mHistogramImageView;
    }


    class LocaleItemData extends ItemData
    {
        String time;
        int stepCount;
        int maxStep;
    }

    private int mHeight;

    public HistogramAdapter(Context c, int h)
    {
        super(c, null , null);
        mHeight = h;
    }


    /**
     * 赋值并刷新界面
     * @param h
     */
    public void initWH(int h)
    {
        mHeight = h;
        notifyDataSetChanged(); // 刷新显示
    }


    public void addStepItem(String time, int setp, int maxStep)
    {
        LocaleItemData data = new LocaleItemData();
        data.time = time;
        data.stepCount = setp;
        data.maxStep = maxStep;
        addItem(data);

    }





    @Override
    protected ViewHolder newViewHolder(View paramView, int paramInt)
    {
        LocalViewHolder holder = new LocalViewHolder();
        holder.mHistogramImageView = (HistogramImageView)paramView.findViewById(R.id.baitian_image);
        return holder;
    }

    @Override
    public synchronized View getView(int position, View convertView, ViewGroup parent)
    {
        if(getCount() == 0)
        {
            return null;
        }
        convertView = newListItemView(parent);
        ViewHolder holder = newViewHolder(convertView, position);
        setListItemData(holder, position);
        return convertView;
    }

    @Override
    protected View newListItemView(ViewGroup paramViewGroup)
    {
        return LayoutInflater.from(mContext).inflate(R.layout.ce_attention_persion_bt_item, paramViewGroup, false);
    }


    @Override
    protected void setListItemData(ViewHolder paramViewHolder, int paramInt)
    {
        LocalViewHolder hol = (LocalViewHolder)paramViewHolder;
        LocaleItemData item = (LocaleItemData)getItem(paramInt);

        ViewGroup.LayoutParams params = hol.mHistogramImageView.getLayoutParams();

        params.height = mHeight;
        hol.mHistogramImageView.setLayoutParams(params);
        hol.mHistogramImageView.addData(item.time, item.stepCount, item.maxStep);

        hol.mHistogramImageView.invalidate();










    }


}
